package com.atguigu.day26.day27morning.dbutils07;


import com.atguigu.day26.day27morning.m2dbtuils.JDBCUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.junit.Test;

import java.sql.SQLException;

public class BatchTest {
    @Test
    public void test01() throws SQLException {
        long start = System.currentTimeMillis();
        //1.创建对象
        QueryRunner qr = new QueryRunner(JDBCUtils.getDataSource());
        //2.准备sql
        String sql = "insert into t_account values(null,?,?)";
        //3.准备数据
        //todo 10000 记录数  2 参数个数
        Object[][] params = new Object[10000][2];

        for (int i = 0; i < params.length; i++) {
            //一个一维数组 对应一条记录
            params[i][0] = "黄芪"+i;
            params[i][1]=i+1;
        }
        //4.执行批处理
        qr.batch(sql,params);
        long end = System.currentTimeMillis();
        System.out.println(end-start);
    }
}
